{% extends 'store_admin/inventory/base_carts.html' %}
{% load i18n %}
{% load sell_tags %}
{% load store_admin_tags %}

{% block title_menu_left %}{% trans "Shopping Carts" %}{% endblock %}

{% block toolbar %}
    {{ block.super }}
    
    <script type="text/javascript">
		function delete_all(){
			if (confirm("Are you sure you want to delete this items?")){
				$("#items_selection").submit();
			}
		};
	</script>

    <a id="item_bulk_delete" style="cursor: pointer" onclick="javascript:delete_all()"><img src="{{ MEDIA_URL }}img/remove.png" class="icon"/>{% trans "Delete Items" %}</a>
    
	<form method="get" action="." class="form_search">
		<input type="text" name="q_title" value="{{ q_title }}"/>
		<input type="hidden" name="filter_by" value="title"/>
	</form>
{% endblock %}

{% block menu_options %}
	<script type="text/javascript">
		$(function() {
			$("#tree_cat").treeview({
				collapsed: true,
				animated: "fast",
				unique: true,
				persist: "location",
			});
		})		
 	</script>
	 	
	<ul id="tree_cat">
		<li class="open">{% trans "Category" %}
			<ul>
				{% for category in shop.marketplace.marketcategory_set.all %}
					<li><a href="./?filter_by=category&id_category={{ category.id }}">{{ category.name }}</a>
					<ul id="sub_tree">
						{% for subcategory in category.subcategories.all %}
							<li><a href="./?filter_by=subcategory&id_subcategory={{ subcategory.id }}">{{ subcategory.name }}</a></li>
						{% endfor %}
					</ul>
					</li>
				{% endfor %}
			</ul>
		</li>
	</ul>
{% endblock %}

{% block super_main %}

	<div class="bar_title">
		<div class="grid_1 alpha omega bar_column" style="width: 30px;">
			&nbsp;
		</div>
		<div class="grid_1 alpha omega bar_column">
			<a href="./?{{ filter_params|update_filters:'order_by=oldest' }}"><img src="{{ MEDIA_URL }}img/icon_down.gif"/></a>
			<a href="./?{{ filter_params|update_filters:'order_by=newest' }}"><img src="{{ MEDIA_URL }}img/icon_up.gif"/></a>
		</div>
		<div class="grid_1 alpha omega bar_column"><b>{% trans "Date" %}</b></div>
		<div class="grid_9 alpha omega bar_column"><b>{% trans "Items" %}</b></div>
		<div class="grid_2 alpha omega bar_column" style="width: 65px;"><b>{% trans "Total" %}</b></div>
		<div class="grid_2 alpha omega bar_column"><b>{% trans "User" %}</b></div>
		<div class="grid_2 alpha omega bar_column" style="width:65px;"><b>{% trans "Notify" %}</b></div>
		<div class="clear"></div>
	</div>
	
	<form action="{% url delete_cart_items %}" method="POST" id="items_selection" >
		{% for cart in carts.object_list %}
			{% if cart.total_items > 0 %}
			<div class="{% cycle 'row_1' 'row_2' %} carts_list" title="Shopping Cart ID: {{ cart.id }}">
				<div class="grid_1 alpha omega column" style="width: 30px;"><input type="checkbox" name="{{ cart.id }}"/></div>
				<div class="grid_1 alpha omega column"># {{ cart.id }}</div>
				<div class="grid_1 alpha omega column"><span>{{ cart.last_update|timesince }}</span></div>
				<div class="grid_9 alpha omega column">
					<div class="grid_1 alpha omega bar_column"><b>{% trans "ID" %}</b></div>
					<div class="grid_5 alpha omega bar_column"><b>{% trans "Title" %}</b></div>
					<div class="grid_1 alpha omega bar_column"><b>{% trans "Qty" %}</b></div>
					<div class="grid_1 alpha omega bar_column" style="width: 82px;"><b>{% trans "Sub T" %}</b></div>
					{% for item in cart.cartitem_set.all %}
						{% if item.product.id %} {# the product may have been deleted #}
							<div>
								<div class="grid_1 alpha omega column">
									<a href="{% url item_details item.product.id %}" target="_blank"># {{ item.product.id }}</a>
								</div>
								<div class="grid_5 alpha omega column">
									{{ item.product.title }}
								</div>
								<div class="grid_1 alpha omega column">
									{{ item.qty }}
								</div>
								<div class="grid_1 alpha omega column" style="width: 82px;">
									{{ item.sub_total }}
								</div>
								<div class="clear"></div>
							</div>
						{% else %}
							<div class="grid_1 alpha omega column"><a>&nbsp</a></div>
							<div class="grid_5 alpha omega column">
								<p>Product not found in the inventory</p>
							</div>
						{% endif %}
					{% endfor %}	
				</div>
				<div class="grid_2 alpha omega column" style="width: 65px;"><span>${{ cart.total }}</span></div>
				<div class="grid_2 alpha omega column"><a href="{% url buyer_info cart.id %}" target="_blank">{{ cart.bidder.username }}</a></div>
				<div class="grid_2 alpha omega column" style="width:65px;"><a title="Send notification to {{ cart.bidder.email }}" href="{% url notify_to_buyer cart.id %}">{% trans "Notify Buyer" %}</a></div>
				<div class="clear"></div>
			</div>
			{% endif %}
		{% endfor %}
	</form>
	
	{% block main %}
		<div class="clear"></div>
		{% if total > 10 %}
		<div>
			<br></br>
			{% trans "Show Results By" %} 
			{% if filter_params.items_per_page != 10 %}<a href="./?{{ filter_params|update_filters:'items_per_page=10' }}">10</a>{% else %}<b>10</b>{% endif %} |
			{% if filter_params.items_per_page != 20 %}<a href="./?{{ filter_params|update_filters:'items_per_page=20' }}">20</a>{% else %}<b>20</b>{% endif %} | 
			{% if filter_params.items_per_page != 50 %}<a href="./?{{ filter_params|update_filters:'items_per_page=50' }}">50</a>{% else %}<b>50</b>{% endif %} | 
			{% if filter_params.items_per_page != 100 %}<a href="./?{{ filter_params|update_filters:'items_per_page=100' }}">100</a>{% else %}<b>100</b>{% endif %}
		</div>
		{% endif %}
		<div class="pagination">
		{% with carts as objects %}
			{% include 'paginator.html'%}
		{% endwith %}
		</div>
		<div class="clear"></div>
		<hr/>

	{% endblock %}

{% endblock %}
